package com.eastfair.point.controller;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.log.point.PointUtil;
import com.eastfair.mq.model.MySimpleMessage;
import com.eastfair.mq.util.MessageKeyUtil;
import com.eastfair.point.business.auth.BusinLoadUserPermissOfRolePoint;
import com.eastfair.point.business.auth.BusinLoadUserPermissPoint;
import com.eastfair.point.dao.TestCollectionDao;
import com.eastfair.point.entity.TestCollection;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.eastfair.core.base.R;
import com.eastfair.point.orderbusiness.OrderUserPoint;
import com.eastfair.point.point.OrderTransaction;
import com.eastfair.point.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 前端控制器
 * 用户账户信息
 * </p>
 *
 * @author ligang
 * @date 2021-08-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/test")
@Api(value = "test", tags = "用户账户信息")
public class TestCollectionController {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Autowired
    TestCollectionDao testCollectionDao;

    @Value("${rocketmq.consumer.transactionTopic}")
    private String transactionTopic;

    @Autowired
    private OrderService orderService;

    @Autowired
    PointUtil pointUtil;

//    @RequestMapping(value = "/add", method = RequestMethod.GET)
//    @ResponseBody
//    public R add() {
//        TestCollection testCollection = new TestCollection();
//        testCollection.setBookId("111111111111111");
//        testCollection.setSchoolId("999999999999");
//        testCollection.setDate(new Date());
//        testCollectionDao.add(testCollection);
//        return R.success(testCollection);
//    }


    @RequestMapping(value = "/sentran", method = RequestMethod.GET)
    @ResponseBody
    @SysLog("分布式半事务例子")
    public R sentran() {

        /********提交订单********/
        log.info("链路id: "+ContextUtil.getTrace());
        OrderTransaction orderTransaction = new OrderTransaction();
        orderTransaction.setOrderNumber("111222");
        orderTransaction.setCommodityId("123456");
        orderTransaction.setStore(2);
        //发送队列
        orderService.sendQueueMessage(orderTransaction);
        //由于是队列，所以需要等待时间才能出结果

        return R.success();
    }



    /**
     * 查询菜单全部子信息
     *
     * @param id 菜单idLogAutoConfiguration
     * @return 查询结果
     */
    @ApiOperation(value = "查询菜单全部子信息", notes = "查询菜单全部子信息")
    @GetMapping("/test")
    public R test(Long id) {

//        LogPoint logPoint = new LogPoint();
//        logPoint.setEmail("数据步骤1");
//        logPoint.setMsg("操作记录1");
//        pointUtil.addLogPointMsg(logPoint);


//        OrderUserPoint orderUserPoint = new OrderUserPoint();
//        orderUserPoint.setUserId(1111L);
//        orderUserPoint.setOrderPointOrderId("3333阿达打发");
//        pointUtil.addOrderBusinPointMsg(orderUserPoint);
//
//        orderUserPoint = new OrderUserPoint();
//        orderUserPoint.setOrderPointOrderId("3333阿达打发");
//        orderUserPoint.setUserId(2222L);
//        pointUtil.addOrderBusinPointMsg(orderUserPoint);
//
//        orderUserPoint = new OrderUserPoint();
//        orderUserPoint.setUserId(1111L);
//        orderUserPoint.setOrderPointOrderId("3333");
//        pointUtil.addOrderBusinPointMsg(orderUserPoint);
//
//        orderUserPoint = new OrderUserPoint();
//        orderUserPoint.setOrderPointOrderId("3333");
//        orderUserPoint.setUserId(2222L);
//        pointUtil.addOrderBusinPointMsg(orderUserPoint);

        BusinLoadUserPermissOfRolePoint businLoadUserPermissOfRolePoint = new BusinLoadUserPermissOfRolePoint();
        businLoadUserPermissOfRolePoint.setProjectId(11111L);
        businLoadUserPermissOfRolePoint.setRoleIdList(Arrays.asList(111L, 222L));
        pointUtil.addBusinPointMsg(businLoadUserPermissOfRolePoint);

        BusinLoadUserPermissPoint businLoadUserPermissPoint = new BusinLoadUserPermissPoint();
        businLoadUserPermissPoint.setUserIdList(Arrays.asList(3333333L));
        businLoadUserPermissPoint.setProjectId(44444L);
        pointUtil.addBusinPointMsg(businLoadUserPermissPoint);
        return null;
    }
}
